<?php
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('home', 'payment');
$this->breadcrumbs = array(
    Yii::t('home', 'payment')
);

if (Yii::app()->user->isGuest) {
    $baseUrl = Yii::app()->getBaseUrl(true);
    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'mydialog',
        // additional javascript options for the dialog plugin
        'options' => array(
            'title' => Yii::t('home', 'message'),
            'autoOpen' => true,
            'modal' => true,
            'beforeClose' => 'js:function(){window.location = "' . $baseUrl . '/index.php?r=index";}',
            'buttons' => array(
                Yii::t('home', 'close') => 'js:function(){window.location = "' . $baseUrl . '/index.php?r=login";}'
            ),
        ),
    ));

    echo Yii::t('home', 'require_login');

    $this->endWidget('zii.widgets.jui.CJuiDialog');
    return;
}
?>
<div id="focus" class="wrapper row100 bgded" style="background-image:url('images/live-demo/background-03.jpg');">
    <div class="overlay">
        <div id="newsletter" class="clear center">
            <h2 class="uppercase font-x3 btmspace-50"><?= Yii::t('payment', 'payment') ?></h2>
            <?php
            $order = $model->getPaymentOrder();

            if (!isset($order)) {
                echo "<p>" . Yii::t('payment', 'no_items') . "</p>";
                return;
            }
            ?>

            <div class="form">
                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id' => 'payment-form',
                    'enableClientValidation' => true,
                    'clientOptions' => array(
                        'validateOnSubmit' => true,
                    ),
                ));
                ?>

                <div class="row">
                    <p>
                        <?php echo $form->labelEx($model, 'order'); ?>
                        <?php echo CHtml::link($order->order_id, array('payment/vieworder&id=' . $order->order_id)); ?>
                        <?php echo $form->hiddenField($model, 'order', array('value' => $order->order_id)); ?>
                    </p>
                </div>

                <div class="row">
                    <?php
                    echo $form->dropDownList($model, 'bank', array('' => Yii::t('payment', 'bank'),
                        Yii::t('bank', 'the_siam_commercial') => Yii::t('bank', 'the_siam_commercial'),
                        Yii::t('bank', 'kasikorn') => Yii::t('bank', 'kasikorn'),
                        Yii::t('bank', 'bangkok') => Yii::t('bank', 'bangkok'),
                    ));
                    ?>
                    <?php echo $form->error($model, 'bank'); ?>
                </div>

<!--                <div class="row">
                    <?php echo $form->textField($model, 'bankBranch', array('placeholder' => Yii::t('payment', 'bank_branch'))); ?>
                    <?php echo $form->error($model, 'bankBranch'); ?>
                </div>-->

                <div class="row">
                    <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'attribute' => 'payment_date',
                        'model' => $model,
                        'name' => 'payment_date',
                        'options' => array(
                            'defaultDate' => date('Y-m-d'),
                            'showButtonPanel' => false,
                            'showAnim' => 'slide',
                            'dateFormat' => 'yy-mm-dd',
                            'dayNamesMin' => Yii::t('register', 'short_days'),
                            'monthNamesShort' => Yii::t('register', 'months'),
                            'changeMonth' => true,
                            'changeYear' => true,
                            'yearRange' => '1900:2099',
                            'beforeShow' => 'js:function(){  
                    if($(this).val() != ""){
                        var arrayDate = $(this).val().split("-");  
                        if (parseInt(arrayDate[0]) > 2400) {
                            arrayDate[0] = parseInt(arrayDate[0]) - 543;
                        }
                        $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);
                    }
                    setTimeout(function(){
                        $.each($(".ui-datepicker-year option"), function(j, k){
                            var textYear = "";
                            if(parseInt($(".ui-datepicker-year option").eq(j).val()) < 2400){
                                textYear = parseInt($(".ui-datepicker-year option").eq(j).val()) + 543;
                            }
                            $(".ui-datepicker-year option").eq(j).text(textYear);
                        });             
                    },50);
                }',
                            'afterRender' => 'js:function(){  
                    alert("sss");
                }',
                            'onClose' => 'js:function(){
                    if($(this).val() != "" && $(this).val() == dateBefore){         
                        var arrayDate = dateBefore.split("-");
                        if (parseInt(arrayDate[0]) < 2400) {
                            arrayDate[0] = parseInt(arrayDate[0]) + 543;
                        }
                        $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);    
                    }       
                }',
                            'onSelect' => 'js:function(dateText, inst){ 
                    dateBefore = $(this).val();
                    var arrayDate = dateText.split("-");
                    if (parseInt(arrayDate[0]) < 2400) {
                        arrayDate[0] = parseInt(arrayDate[0]) + 543;
                    }
                    $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);
                }',
                        ),
                        'htmlOptions' => array(
                            'value' => (date('Y') + 543) . date('-m-d'),
                            'onFocus' => 'this.value = ""',
                            'placeholder' => Yii::t('payment', 'payment_date')
                        ),
                    ));
                    ?>
                    <?php echo $form->error($model, 'payment_date'); ?>
                </div>

                <div class="row">
                    <?php
                    $this->widget('application.extensions.timepicker.EJuiDateTimePicker', array(
                        'model' => $model,
                        'name' => 'PaymentForm[time]',
                        'id' => 'PaymentForm_time',
                        'value' => '',
                        'options' => array(
                            'showOn' => 'focus',
                            'timeFormat' => 'hh:mm',
                            'timeOnly' => true,
                        ),
                        'htmlOptions' => array(
                            'maxlength' => '10', // textField maxlength
                            'placeholder' => Yii::t('payment', 'time')
                        ),
                    ));
                    ?>
                    <?php echo $form->error($model, 'time'); ?>
                </div>

                <div class="row">
                    <?php echo $form->textField($model, 'payment_name', array('value' => $order->name . ' ' . $order->surname, 'placeholder' => Yii::t('payment', 'full_name'))); ?>
                    <?php echo $form->error($model, 'payment_name'); ?>
                </div>

                <div class="row">
                    <?php echo $form->textField($model, 'payment_mobilephone', array('value' => $order->contact_tel, 'placeholder' => Yii::t('order_model', 'contact_tel'))); ?>
                    <?php echo $form->error($model, 'payment_mobilephone'); ?>
                </div>

                <div class="row">
                    <?php echo $form->textField($model, 'amount', array('value' => $order->price, 'placeholder' => Yii::t('payment', 'amount'))); ?>
                    <?php echo $form->error($model, 'amount'); ?>
                </div>

                <div class="row">
                    <?php echo $form->textArea($model, 'remark', array('maxlength' => 300, 'rows' => 6, 'cols' => 50, 'placeholder' => Yii::t('payment', 'remark'))); ?>
                    <?php echo $form->error($model, 'remark'); ?>
                </div>

                <div class="row buttons">
                    <?php echo CHtml::tag('button', array('class' => 'btn', 'type' => 'submit'), Yii::t('payment', 'payment')); ?>
                </div>

                <?php $this->endWidget(); ?>
            </div><!-- form -->
        </div>
    </div>
</div>